<!DOCTYPE html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>京东(JD.COM)-综合网购首选-正品低价、品质保障、配送及时、轻松购物！</title>
    <meta name="description"
        content="京东JD.COM-专业的综合网上购物商城,销售家电、数码通讯、电脑、家居百货、服装服饰、母婴、图书、食品等数万个品牌优质商品.便捷、诚信的服务，为您提供愉悦的网上购物体验!" />
    <meta name="Keywords" content="网上购物,网上商城,手机,笔记本,电脑,MP3,CD,VCD,DV,相机,数码,配件,手表,存储卡,京东" />
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/normalize.css" />
    <link rel="stylesheet" href="css/base.css" />
    <link rel="stylesheet" href="css/pay.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/base.js"></script>
    <script src="js/pay.js"></script>
    <script src="js/axios.min.js"></script>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <!-- import JavaScript -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="js/vue-qriously.js"></script>
</head>
<style>
    #searchBox {
        overflow: hidden;
    }

    #closeSearchBtn {
        color: rgb(71, 67, 67);
        font: 12px/150% tahoma, arial, Microsoft YaHei, Hiragino Sans GB, "\u5b8b\u4f53", sans-serif;
    }

    .address {
        cursor: pointer;
    }
</style>

<body>
    <div id="app">
        <header>
            <a href="#">
                <img src="images/header.jpg" height="80" width="100%" alt="">
            </a>
        </header>
        <div>
            <iframe MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no src="heade.html"
                height="30px" width="100%"></iframe>
        </div>
        <div class="m">
            <div class="w middle">
                <div class="logo">
                    <h1>
                        <!-- 提高权重 便利于搜索引擎优化 -->
                        <a href="index.html" title="京东">京东</a>
                    </h1>
                </div>
                <div class="form">
                    <input id="text" type="text" placeholder="扫描仪">
                    <button><i></i></button>
                </div>
                <div class="shopCar">
                    <i></i><a href="cart.html" class="f10">我的购物车</a><span>8</span>
                </div>
                <div class="hotwords">
                    <a href="#" class="f10">199减100</a>
                    <a href="#">鼠标试用</a>
                    <a href="#">农资7折</a>
                    <a href="#">低至29元</a>
                    <a href="#">抽奖赢空调</a>
                    <a href="#">记忆棉</a>
                    <a href="#">坐垫</a>
                    <a href="#">1分钱买油</a>
                    <a href="#">智能手表</a>
                </div>

                <div class="super">
                    <a href="#"><img src="images/super.png" alt=""></a>
                </div>
            </div>
        </div>
        <div class="content">
            <div class="w">
                <p>填写并核对订单信息</p>
                <div class="content-top">
                    <div class="message" id="searchBox" style="height:95px">
                        <p>收件人信息</p>
                        <div class="address" v-if='currentConsignee != null && currentConsignee != ""'
                            @click='selectAddress'>
                            <span>{{currentConsignee.name}}</span>
                            <p>{{currentConsignee.name}} {{currentConsignee.address}} {{currentConsignee.phone}}</p>
                        </div>
                        <el-button v-if='orderInfo.orderStatus == 0' type="text" style="margin-left:10px"
                            id="closeSearchBtn" @click="closeSearch">
                            更多地址
                            <i :class="showAll ? 'el-icon-arrow-up ': 'el-icon-arrow-down'"></i>
                        </el-button>
                        <div class="address" v-for='(consignee,index) in allConsignee' @click='selectAddress(index)'>
                            <span>{{consignee.name}} {{consignee.address}}</span>
                            <p>{{consignee.name}} {{consignee.address}} {{consignee.phone}}</p>
                        </div>
                    </div>
                    <div class="message">
                        <p>选择支付方式</p>
                        <ul class="m-pay">
                            <li class="current" @click='switchPayType(2)'>
                                <svg t="1637505855522" class="icon" viewBox="0 0 1024 1024" version="1.1"
                                    xmlns="http://www.w3.org/2000/svg" p-id="3134" width="50" height="50">
                                    <path
                                        d="M0 488.96v-30.72C2.56 430.08 7.68 404.48 15.36 378.88c20.48-66.56 53.76-122.88 99.84-171.52C179.2 138.24 256 94.72 340.48 66.56c48.64-15.36 97.28-23.04 145.92-25.6 40.96-2.56 79.36 0 120.32 7.68 33.28 5.12 64 12.8 97.28 25.6 79.36 28.16 148.48 71.68 207.36 133.12 7.68 7.68 12.8 15.36 20.48 23.04-2.56 0-2.56 2.56-5.12 2.56-20.48 10.24-40.96 20.48-61.44 28.16-143.36 66.56-286.72 133.12-430.08 197.12-28.16 12.8-56.32 10.24-81.92-5.12-20.48-12.8-38.4-25.6-58.88-38.4-12.8-10.24-25.6-17.92-40.96-28.16-12.8-7.68-20.48-2.56-20.48 12.8v2.56c2.56 12.8 5.12 25.6 10.24 38.4 25.6 61.44 51.2 120.32 76.8 181.76 7.68 17.92 20.48 25.6 35.84 23.04 10.24 0 20.48-2.56 28.16-7.68 30.72-15.36 58.88-33.28 87.04-51.2 156.16-92.16 309.76-184.32 465.92-276.48 10.24-7.68 23.04-12.8 33.28-20.48 0 2.56 2.56 2.56 2.56 5.12 5.12 10.24 10.24 17.92 12.8 28.16 28.16 61.44 40.96 125.44 35.84 192-2.56 28.16-7.68 56.32-15.36 84.48-17.92 61.44-48.64 115.2-92.16 163.84-51.2 56.32-115.2 99.84-184.32 128-40.96 15.36-81.92 28.16-122.88 35.84-28.16 5.12-56.32 7.68-81.92 7.68h-46.08c-20.48-2.56-40.96-2.56-58.88-5.12-30.72-5.12-61.44-12.8-89.6-23.04H322.56c-12.8 7.68-23.04 15.36-35.84 23.04-28.16 17.92-53.76 33.28-81.92 48.64-5.12 2.56-12.8 5.12-17.92 5.12s-10.24-2.56-10.24-10.24c0-5.12 0-12.8 2.56-17.92 5.12-38.4 12.8-74.24 20.48-112.64 0-5.12 0-7.68-5.12-10.24-15.36-12.8-30.72-23.04-46.08-38.4-51.2-46.08-92.16-102.4-117.76-166.4C20.48 599.04 12.8 568.32 7.68 537.6c-2.56-12.8-2.56-25.6-2.56-40.96-5.12 0-5.12-2.56-5.12-7.68z"
                                        fill="#6BCC03" p-id="3135"></path>
                                </svg>
                            </li>
                            <el-dialog :visible.sync="dialogPayVisible" style="text-align: left" :append-to-body="true"
                                width="300px" @close="closeDialog">

                                <div class="container">
                                    <div class="operate-view" style="height: 350px">
                                        <div class="wrapper wechat">
                                            <div>
                                                <!--显示支付二维码-->
                                                <qriously style="margin-left: 20px;" :value="payObj.codeUrl"
                                                    :size="220"></qriously>
                                                <div style="
                                          text-align: center;
                                          line-height: 25px;
                                          margin-bottom: 40px;
                                        ">
                                                    <h3>请使用微信扫一扫<br />
                                                        扫描二维码支付

                                                    </h3>
                                                    <small style="color: red;">rnm! 退钱!</small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </el-dialog>

                            <li @click='switchPayType(1)'>
                                <svg t="1637506398287" class="icon" viewBox="0 0 1025 1024" version="1.1"
                                    xmlns="http://www.w3.org/2000/svg" p-id="3959" width="50" height="50">
                                    <path
                                        d="M1025.197261 700.226491V196.863872A196.863872 196.863872 0 0 0 828.162352 0h-631.127443A196.863872 196.863872 0 0 0 0 196.863872v630.272256a197.034909 197.034909 0 0 0 197.034909 196.863872h631.127443a197.376983 197.376983 0 0 0 193.956238-162.143311c-51.311174-22.576917-278.790713-119.726073-396.806414-176.681476-89.794555 108.779689-184.036078 173.944881-324.97077 173.944881S63.112744 771.891097 74.401203 666.019041c7.525639-70.125271 55.758143-184.720227 264.765659-165.050943 110.147987 10.433272 160.603975 30.957742 250.39853 60.547185a701.252714 701.252714 0 0 0 57.12644-139.224319H248.346083v-40.364791h197.205946v-70.80942H205.244697v-43.443461h239.452146v-102.622348a19.156172 19.156172 0 0 1 19.840321-15.906464H564.422916v118.0157h256.555871v43.443461H564.422916v70.809421h208.494405a799.941206 799.941206 0 0 1-85.518624 212.599298c61.402372 22.576917 337.798564 106.214131 337.798564 106.214131zM283.921831 791.560381c-149.828629 0-173.602806-94.412561-165.564056-133.922165s51.311174-90.649741 134.435277-90.649741c95.780859 0 181.470519 24.458326 284.434942 74.57224-72.177718 94.070486-161.117087 149.999666-253.306163 149.999666z m0 0"
                                        fill="#09AAF0" p-id="3960"></path>
                                </svg>
                            </li>
                        </ul>
                    </div>
                    <div class="message">
                        <p>送货清单</p>
                        <div class="me-bd" v-for='commodity in commodityList'>
                            <span>订单详情</span>
                            <div class="me-bs">
                                <span style="border: none;cursor: pointer;"
                                    @click='gotoDetail(commodity.commodityInfo.itemNumber)'>
                                    <img :src="commodity.commodityInfo.exhibition" width="100%" alt="">
                                </span>

                                <p>
                                    {{commodity.commodityInfo.exName}}
                                    <i>7天无理由退货</i>
                                </p>
                                <div class="price">￥{{commodity.commodityInfo.price * commodity.number}}</div>
                                <div class="num">X{{commodity.number}}</div>
                            </div>
                        </div>
                    </div>
                    <div class="message clearfix me-line">
                        <dl>
                            <dt>{{countNumber}}件商品，总商品金额：</dt>
                            <dd>¥{{orderInfo.price}}</dd>
                            <dt>运费：</dt>
                            <dd class="mess-red">¥todo</dd>
                        </dl>
                    </div>
                    <div class="me-money">
                        <p>应付总额 ： <span>¥{{orderInfo.price}}</span></p>
                        <p v-if='currentConsignee != null && currentConsignee != ""'>寄送至：{{currentConsignee.address}}
                            收货人：{{currentConsignee.name}} {{currentConsignee.phone}}</p>
                    </div>
                    <a v-if='orderInfo.orderStatus == 1' @click="updateOrderStatus(2)" class="me-commit">确认收货</a>
                    <a v-if='orderInfo.orderStatus == 1' @click='refund'
                        style="background-color: white;color: rgb(179, 20, 20);font-size: 14px;"
                        class="me-commit">申请退款</a>

                    <a v-if='orderInfo.orderStatus == 3'
                        style="background-color: rgb(155, 121, 9);color: rgb(238, 231, 231);font-size: 14px;"
                        class="me-commit">等待退款中</a>


                    <a @click="pay" v-if='orderInfo.orderStatus == 0' class="me-commit">立即支付</a>
                    <a v-if='orderInfo.orderStatus == 2' style="background-color: #ffd161;" class="me-commit">订单已完成</a>
                    <a v-if='orderInfo.orderStatus == -1'
                        style="background-color: rgb(161, 160, 160);color: rgb(255, 255, 255);font-size: 14px;"
                        class="me-commit">交易失败</a>
                </div>
            </div>
        </div>
        <footer>
            <div class="service">
                <!-- 服务模块 -->
                <div class="w">
                    <ul>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                        <li>
                            <h5></h5>
                            <p>品类齐全，轻松购物</p>
                        </li>
                    </ul>
                </div>
            </div>
            <!-- 帮助模块 -->
            <div class="w help">
                <div class="fl">
                    <dl>
                        <dt>购物指南</dt>
                        <dd><a href="#">购物流程</a></dd>
                        <dd><a href="#">会员介绍</a></dd>
                        <dd><a href="#">生活旅行</a></dd>
                        <dd><a href="#">常见问题</a></dd>
                        <dd><a href="#">大家电</a></dd>
                        <dd><a href="#">联系客服</a></dd>
                    </dl>
                    <dl>
                        <dt>配送方式</dt>
                        <dd><a href="#">上门自提</a></dd>
                        <dd><a href="#">211限时达</a></dd>
                        <dd><a href="#">配送服务查询</a></dd>
                        <dd><a href="#">配送费收取标准</a></dd>
                        <dd><a href="#">海外配送</a></dd>
                    </dl>
                    <dl>
                        <dt>支付方式</dt>
                        <dd><a href="#">货到付款</a></dd>
                        <dd><a href="#">在线支付</a></dd>
                        <dd><a href="#">分期付款</a></dd>
                        <dd><a href="#">邮局汇款</a></dd>
                        <dd><a href="#">公司转账</a></dd>
                    </dl>
                    <dl>
                        <dt>售后服务</dt>
                        <dd><a href="#">售后政策</a></dd>
                        <dd><a href="#">价格保护</a></dd>
                        <dd><a href="#">退款说明</a></dd>
                        <dd><a href="#">返修/退换货</a></dd>
                        <dd><a href="#">取消订单</a></dd>
                    </dl>
                    <dl>
                        <dt>特色服务</dt>
                        <dd><a href="#">夺宝岛</a></dd>
                        <dd><a href="#">DIY装机</a></dd>
                        <dd><a href="#">延保服务</a></dd>
                        <dd><a href="#">京东E卡</a></dd>
                        <dd><a href="#">京东通信</a></dd>
                        <dd><a href="#">京鱼座智能</a></dd>
                    </dl>
                </div>
                <div class="fr coverage">
                    <h5>京东自营覆盖区县</h5>
                    <p>京东已向全国2661个区县提供自营配送服务，支持货到付款、POS机刷卡和售后上门服务。</p>
                    <a href="#">查看详情 > </a>
                </div>
            </div>
            <div class="w copyright">
                <p>
                    <a href="#">关于我们</a>
                    <span> | </span>
                    <a href="#">联系我们</a>
                    <span> | </span>
                    <a href="#">联系客服</a>
                    <span> | </span>
                    <a href="#">合作招商</a>
                    <span> | </span>
                    <a href="#">商家帮助</a>
                    <span> | </span>
                    <a href="#">营销中心</a>
                    <span> | </span>
                    <a href="#">手机京东</a>
                    <span> | </span>
                    <a href="#">友情链接</a>
                    <span> | </span>
                    <a href="#">销售联盟</a>
                    <span> | </span>
                    <a href="#">京东社区</a>
                    <span> | </span>
                    <a href="#">风险监测</a>
                    <span> | </span>
                    <a href="#">隐私政策</a>
                    <span> | </span>
                    <a href="#">京东公益</a>
                    <span> | </span>
                    <a href="#">English Site</a>
                    <span> | </span>
                    <a href="#">Media & IR</a>
                </p>
                <div>
                    <p>京公网安备
                        11000002000088号<span>|</span>京ICP证070359号<span>|</span>互联网药品信息服务资格证编号(京)-经营性-2014-0008<span>|</span>新出发京零
                        字第大120007号</p>
                    <p>互联网出版许可证编号新出网证(京)字150号<span>|</span>出版物经营许可证<span>|</span>网络文化经营许可证京网文[2014]2148-348号<span>|</span>违法和不良信息举报电话：4006561155
                    </p>
                    <p>Copyright © 2004 - 2019 京东JD.com
                        版权所有<span>|</span>消费者维权热线：4006067733经营证照|(京)网械平台备字(2018)第00003号<span>|</span>营业执照</p>
                    <p>Global Site<span>|</span>Сайт России<span>|</span>Situs Indonesia<span>|</span>Sitio de
                        España<span>|</span>เว็บไซต์ประเทศไทย</p>
                    <p>京东旗下网站：京东钱包<span>|</span>京东云</p>
                </div>
                <p class="foot-icon">
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                    <a href="#"></a>
                </p>
            </div>
        </footer>
        <form id="aliPay" action='http://localhost/api/order/alipay/createOrder' method="get"  target="_blank" >                           
            <input type="hidden" name="orderId" :value="orderId">
        </form> 
    </div>
    
 
</body>

</html>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                commodityList: {},//存放商品对象
                orderInfo: '',//存放订单信息
                token: '',//用户id
                orderId: '',//订单编号
                countNumber: 0,//商品总数量
                showAll: false,//是否展开全部
                currentConsignee: '',//当前收货人信息
                allConsignee: {},//所有收货人信息
                payType: 2,//支付类型
                dialogPayVisible: false,
                payObj: {
                    codeUrl: undefined
                },
                timer: null, // 定时器名称
            }
        },
        created() {
            this.showInfo();
            this.orderId = this.GetURLParameter("orderId");
            this.getCommodityByOrderId();
            this.getConsigneeByUerId();
        },
        method() {
            /**
             * 收起搜索
             */
            this.$nextTick(function () {
                this.closeSearch();
            });
        },
        methods: {
            showInfo() {
                let token = this.getCookie("token");
                if (token == "" || token == null) {
                    // window.location.href = 'login.html';
                } else {
                    this.token = token;
                }
            },
            //根据订单编号查询商品信息
            getCommodityByOrderId() {
                let param = new URLSearchParams()
                param.append('orderId', this.orderId)
                axios.post(`http://localhost/admin/order/getCommodityByOrderId`, param)
                    .then(response => {
                        let resData = response.data;
                        this.orderInfo = resData.data;
                        this.commodityList = resData.data.param.commodityInfoList;
                        this.currentConsignee = resData.data.param.consigneeInfo;
                        this.commodityList.forEach(commodity => {
                            this.countNumber += commodity.number;
                        });
                    })
            },
            //根据用户id查询收货人信息
            getConsigneeByUerId() {
                let param = new URLSearchParams()
                param.append('token', this.token);
                axios.post(`http://localhost/admin/user/consignee/getConsigneeByUerId`, param)
                    .then(response => {
                        let resData = response.data;
                        this.allConsignee = resData.data;
                    })
            },
            switchPayType(type) {
                console.log(type);
                this.payType = type;
            },
            //生成支付二维码
            pay() {
                if (this.currentConsignee == '' || this.currentConsignee == null) {
                    alert("请填写收货人信息")
                    return;
                }
                if (this.payType == 1) {
                    //调用支付宝接口
                    this.aliPay();
                } else {
                    //调用微信接口
                    this.weixinPay();
                }

            },
            aliPay(){
                $("#aliPay").submit();
                        this.$confirm('是否支付成功', '提示', {
                            confirmButtonText: '是',
                            cancelButtonText: '否',
                            type: 'warning'
                            }).then(() => {
                                //查询支付状态
                                axios.get(`http://localhost/api/order/alipay/queryPayStatus/${this.orderId}`)
                                .then(response => {
                                    if(response.data.data == true){
                                        window.location.reload();
                                    }else{
                                        alert("暂未查询到该订单支付记录")
                                    }
                                })
                            })  
            },
            weixinPay() {
                //支付二维码弹框显示
                this.dialogPayVisible = true;
                axios.get(`http://localhost/api/order/weixin/createNative/${this.orderId}`)
                    .then(response => {
                        this.payObj = response.data.data;
                        console.log(this.payObj.codeUrl)
                        if (this.payObj.codeUrl == '' || this.payObj.codeUrl == null) {//生成失败
                            this.dialogPayVisible = false;
                            this.$message.error("支付错误");
                        } else {
                            //每隔3秒钟调用查询支付状态接口
                            this.timer = setInterval(() => {
                                this.queryPayStatus(this.orderId);
                            }, 3000);
                        }
                    })
            },
            //查询支付状态
            queryPayStatus(orderId) {
                axios.get(`http://localhost/api/order/weixin/queryPayStatus/${this.orderId}`)
                    .then(response => {
                        if (response.data.message == '支付中') {
                            return;
                        } else {
                            //清除定时器
                            clearInterval(this.timer);
                            window.location.reload();
                            this.$message({
                                showClose: true,
                                message: '恭喜你，支付成功!',
                                type: 'success'
                            });
                        }

                    })

            },
            //申请退款
            refund() {
                axios.post(`http://localhost/admin/order/userRefund/${this.orderId}`    )
                    .then(response => {
                        console.log(response)
                        if (response.data.code == 200) {
                            alert("申请成功,退款结果会以短信方式通知您，请耐心等待!")
                            window.location.reload();
                        } else {
                            alert(response.data.message)
                        }
                    })
            },
            closeDialog() {
                if (this.timer) {
                    clearInterval(this.timer);
                }
            },
            closeDialog() {
                if (this.timer) {
                    clearInterval(this.timer);
                }
            },
            //跳转至详情页
            gotoDetail(itemNumber) {
                window.open('detail.html?itemNumber=' + itemNumber);
            },
            //修改收货人信息
            selectAddress(index) {
                let param = new URLSearchParams();
                param.append('orderId', this.orderId);
                param.append('consigneeId', this.allConsignee[index].id);
                axios.post(`http://localhost/admin/order/updateConsignee`, param)
                    .then(response => {
                        //更换收货人地址，并收起菜单
                        this.currentConsignee = this.allConsignee[index];
                        this.showAll = true;
                        this.closeSearch();
                    })

            },
            //更新订单状态
            updateOrderStatus(status) {
                axios.post(`http://localhost/admin/order/updateOrderStatus/${this.orderId}/2`)
                    .then(response => {
                        alert("交易成功");
                        window.location.href = 'order.html';
                    })
            },
            word: function () {
                if (this.showAll == false) {
                    //对文字进行处理
                    return "展开搜索";
                } else {
                    return "收起搜索";
                }
            },
            closeSearch() {
                this.showAll = !this.showAll;
                var searchBoxHeght = document.getElementById("searchBox");
                if (this.showAll == false) {
                    searchBoxHeght.style.height = 100 + "px";
                } else {
                    searchBoxHeght.style.height = "auto";
                }
            },
            GetURLParameter(sParam) {
                let sPageURL = window.location.search.substring(1);
                let sURLVariables = sPageURL.split("&");
                for (let i = 0; i < sURLVariables.length; i++) {
                    let sParameterName = sURLVariables[i].split('=');
                    if (sParameterName[i] == sParam) {
                        return sParameterName[i + 1];
                    }
                }
            },
            getCookie(name) {
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg)) {
                    return unescape(arr[2]);

                } else {
                    return null;
                }
            },

        }
    })
</script>


<style>
    .info-wrapper {
        padding-left: 0;
        padding-top: 0;
    }

    .content-wrapper {
        color: #333;
        font-size: 14px;
        padding-bottom: 0;
    }

    .bottom-wrapper {
        width: 100%;
    }

    .button-wrapper {
        margin: 0;
    }

    .el-form-item {
        margin-bottom: 5px;
    }

    .bottom-wrapper .button-wrapper {
        margin-top: 0;
    }
</style>